package de.gameduell.framework.gui.popup {
	import fl.containers.ScrollPane;

	import de.gameduell.framework.gui.popup.Popup;
	import de.gameduell.framework.gui.scroll.ScrollList;
	import de.gameduell.framework.locale.LocaleData;
	import de.gameduell.framework.util.Library;

	import flash.display.MovieClip;

	/**
	 * A basic setup of a result popup which is part of almost every gultiplayer game.
	 */
	public class MultiplayerResultPopup extends Popup {

		protected var totalScoreFields:Array;
		protected var scrollList:ScrollList;
		protected var localeData:LocaleData;
		protected var players:Array;

		/**
		 * Inititalize all popup settings.
		 * 
		 * @param libraryID		library id of the popup clip
		 * @param popupTime		max. time the popup is displayed
		 * @param isDraggable	if true the popup is draggable
		 * @param scrollPaneID	override the default instance name
		 */
		public function MultiplayerResultPopup(libraryID:String, popupTime:int = 20000, isDraggable:Boolean = true, scrollPaneID:String = "scrollPane"){
			super(libraryID, libraryID, popupTime, isDraggable);
			
			library    = Library.getInstance();
			localeData = LocaleData.getInstance();
			scrollList = new ScrollList(_sprite.getChildByName(scrollPaneID) as ScrollPane);
			initNamesAndAvatars();
		}
		
		/** override this function with your game specific code */
		protected function initNamesAndAvatars():void {}
		
		/**
		 * Adds a movie clip to the scrollpane.
		 * 
		 * @param aResultClip	clip to be added
		 * @param currentRound	a number to set the clip to the next possible position
		 */
		protected function addResult(aResultClip:MovieClip, currentRound:int):void {
			aResultClip.y = currentRound * aResultClip.height;
			scrollList.addItem(aResultClip);
			scrollList.scrollToBottom();
		}
	}
}